import SysApi from '@/platform/apis/sys-api';
import HttpResultUtils from '@/platform/commons/utils/http-result-util';
import SysStorageUtils from '@/platform/commons/utils/sys-storage-util';
import React, { useEffect, useState } from 'react';
import LeftToolbar from './component/left-toolbar/LeftToolbar';
import RightMain from './component/right-main/RightMain';
import classes from './AdminLayout.module.less';

const AdminLayout:React.FC<{route:any}> = ({ route }:any) => {
    const [mainData, setMainData] = useState({
        userData: {},
        menuData: []
    });

    const initMain = () => {
        SysApi.initMainData().then((result) => {
            if (HttpResultUtils.isSuccess(result)) {
                const userData = result.data.resultData.userData;
                let menuData = [];
                if (
                    result.data.resultData.menuData
                    && result.data.resultData.menuData[0]
                    && result.data.resultData.menuData[0].children
                ) {
                    menuData = result.data.resultData.menuData[0].children;
                }

                setMainData({
                    userData,
                    menuData
                });
  
                SysStorageUtils.setSessionUserInfo(result.data.resultData.userData);
                //initWaterMarkerOpts(result.data.resultData.userData);
            } else {
                HttpResultUtils.failureTipMsg(result);
            }
        });
    };

    useEffect(() => {
        initMain();
    }, []);

    return (
        <div className={classes["app-admin-layout-container"]}>
            <LeftToolbar menuData={mainData.menuData} userData={mainData.userData} fixedNavMenu />
            <RightMain route={route} />
        </div>
    ) 
};

export default AdminLayout;
